package com.haojii.jdo.basic;

import java.util.Date;

import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.KeyFactory;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class UserEncodedString {
    	
	@PrimaryKey 
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) 
    @Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true") 
    private String encodedKey;
	@Extension(vendorName="datanucleus", key="gae.pk-name", value="true")
    private String keyName;
	//"gae.pk-name" 字段可以在保存对象前设置为键名称。保存对象时，将使用包括键名称的完整键填充编码键字段。其类型必须为 String。
	@Persistent
	private Date date = new Date();
	@Persistent
	private String name;
	@Persistent
	private String type;
	
	public UserEncodedString() {
		
	}
	public UserEncodedString(String keyName, String name, String type) {
		super();
		this.encodedKey = KeyFactory.keyToString(KeyFactory.createKey(UserEncodedString.class.getSimpleName(), keyName));
		this.keyName = keyName;
		this.name = name;
		this.type = type;
	}

	

	

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getEncodedKey() {
		return encodedKey;
	}

	public void setEncodedKey(String encodedKey) {
		this.encodedKey = encodedKey;
	}

	public String getKeyName() {
		return keyName;
	}

	public void setKeyName(String keyName) {
		this.keyName = keyName;
	}

	@Override
	public String toString() {
		return "UserEncodedString [date=" + date + ", encodedKey=" + encodedKey
				+ ", keyName=" + keyName + ", name=" + name + ", type=" + type
				+ "]";
	}
}
